<template>
  <el-form :inline="true" :model="values" class="demo-form-inline">
    <el-form-item label="关键字">
      <el-input v-model="values.search" />
    </el-form-item>
    <el-form-item label="分类">
      <el-select clearable v-model="values.category" >
        <el-option v-for="item in categories" :key="item" :label="item" :value="item" />
      </el-select>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">搜索</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import { getProCategoriesApi } from '@/api/pro'
export default {
  name: 'GoodProSearch',
  emits: ['search'],
  data () {
    return {
      values: {
        category: '',
        search: ''
      },
      categories: []
    }
  },
  methods: {
    onSubmit () {
      const { category, search } = this.values
      this.$emit('search', category, search)
    },
    async getCategories () {
      try {
        this.categories = await getProCategoriesApi()
      } catch (error) {}
    }
  },
  mounted () {
    this.getCategories()
  }
}
</script>